package file_1;

import java.io.File;
import java.io.FileFilter;

public class FileDemo2 {
    public static void main(String[] args) {
      /*  File dir = new File(".");
        if (dir.isDirectory()) {
            File[] subs = dir.listFiles(f -> f.getName().contains("s"));
            for (File sub : subs) {
                System.out.println(sub.getName());
            }
        } else {
            System.out.println("该目录不存在");
        }*/
        File dir = new File(".");
       FileFilter filter = new FileFilter() {
           @Override
           public boolean accept(File pathname) {
               String name = pathname.getName();
               return name.contains("s");
           }
       };
       if (dir.isDirectory()){
           File[] subs = dir.listFiles(filter);
           for (int i = 0 ; i < subs.length; i++){
               System.out.println(subs[i].getName());
           }
       }
    }
}
